/*
 * Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.huawei.csi.tool.domain;

import com.huawei.csi.tool.domain.score.*;
import javafx.scene.control.TreeItem;

import java.util.LinkedList;
import java.util.List;

/**
 * 得分情况 在 扫描文件后（或者异步？）对该类进行属性设置
 *
 * @author lxw
 */
public class Score {
    /**
     * INSTANCE
     */
    private static final Score INSTANCE = new Score();
    /**
     * 开发规则 (30)
     */
    private final DevScore devScore = new DevScore();
    /**
     * 文档完备度 (20)
     */
    private final DocCompletenessScore docCompletenessScore = new DocCompletenessScore();
    /**
     * 静态扫描 (20)
     */
    private final StaticScanScore staticScanScore = new StaticScanScore();
    /**
     * 提供覆盖率执行脚本和报告 (20)
     */
    private final LltScore lltScore = new LltScore();
    /**
     * 升级到仓颉最新版本 (10)
     */
    private final VersionScore versionScore = new VersionScore();


    private Score() {
    }

    public static Score getInstance() {
        return INSTANCE;
    }


    /**
     * @param value   判断是需要初始化那种类型
     * @param isValid 校验是否成功
     **/
    public void initScore(String value, boolean isValid) {
        devScore.calculateScore(value, isValid);
    }

    public int getBeforeScore() {
        return devScore.beforeVerifyScore() + docCompletenessScore.beforeVerifyScore() +
                staticScanScore.beforeVerifyScore() + lltScore.beforeVerifyScore() +
                versionScore.beforeVerifyScore();
    }

    public int getAfterScore() {
        return devScore.afterVerifyScore() + docCompletenessScore.afterVerifyScore() +
                staticScanScore.afterVerifyScore() + lltScore.afterVerifyScore() +
                versionScore.afterVerifyScore();
    }

    public TreeItem<String> getRoot() {
        TreeItem<String> root = new TreeItem<>("得分情况  " + getAfterScore() + "/" + getBeforeScore());
        root.getChildren().addAll(getAllTreeItem());
        return root;
    }

    private List<TreeItem<String>> getAllTreeItem() {
        List<TreeItem<String>> list = new LinkedList<>();
        list.add(devScore.treeItem());
        list.add(docCompletenessScore.treeItem());
        list.add(staticScanScore.treeItem());
        list.add(lltScore.treeItem());
        list.add(versionScore.treeItem());
        return list;
    }


    public DevScore getDevScore() {
        return devScore;
    }


    public DocCompletenessScore getDocCompletenessScore() {
        return docCompletenessScore;
    }


    public StaticScanScore getStaticScanScore() {
        return staticScanScore;
    }


    public LltScore getLltScore() {
        return lltScore;
    }


    public VersionScore getVersionScore() {
        return versionScore;
    }
}
